#include<bits/stdc++.h>
#include <assert.h>
using namespace std;

class mystring
{
    public:
    //mystring();
    mystring(const char * res=nullptr);
    mystring(const mystring &res);
    mystring& operator=(const mystring& res);
    mystring& operator=(const char *s);
    char& operator[](int i);
    const char &operator[](int i) const;
    int size();
    char *getstr();
    ~mystring();
    char *mydata;
    int len;
};
mystring::mystring(const char* res)
{
    if(res==nullptr)
    {
        mydata=new char[1];
        *mydata='\0';
        len=strlen(mydata);
    }
    else
    {
        len=strlen(res);
        mydata=new char[len+1];
        strcpy(mydata,res);
    }
}
mystring::~mystring()
{
    if(mydata!=nullptr)
    {
        delete[]mydata;
        mydata=nullptr;
    }
}
mystring::mystring(const mystring & res)
{
     len=strlen(res.mydata);
    mydata=new char[len+1];
    strcpy(mydata,res.mydata);
}
mystring& mystring::operator = (const mystring & res)
{
    if(this==&res)
    return *this;

    delete[] mydata;
     len=strlen(res.mydata);
    mydata=new char[len+1];
    strcpy(mydata,res.mydata);
    return *this;
}
char& mystring::operator[](int i)
{
    return mydata[i];
}
int mystring::size()
{
    return len;
}
char * mystring::getstr()
{
    return mydata;
}
ostream& operator<<(ostream &os,const mystring &s)
{
    os<<s.mydata;
    return os;
}



////////////////////////////////////////////
char *mystrcpy(char* des,const char* src)
{
    assert(des!=nullptr&&src!=nullptr);
    char *add=des;
    while((*des++ = *src++)!='\0');
    return add;
}
int mystrlen(const char* str)
{
    assert(str!=nullptr);
    int len=0;
    while((*str++)!='\0')++len;
    return len;
}
char *mystrcat(char *des,const char* src)
{
    assert(des!=nullptr&&src!=nullptr);
    char *addr=des;
    while(*des!='\0')++des;
    while(*des++ = *src++);
    return addr;
}
int mystrcmp(const char *s1,const char *s2)
{
    assert(s1!=nullptr&&s2!=nullptr);
    while(*s1 == *s2)
    {
        if(*s1=='\0')return 0;
        ++s1;
        ++s2;
    }
    return *s1-*s2;
}

int main()
{
char p1[]="we";
char p2[]="hello ha ofkosakfos ";
//char *res=mystrcpy(p2,p1);
char *res2=strcat(p2,p1);
//cout<<res<<'\n';
cout<<res2<<'\n';
cout<<mystrlen(p2)<<'\n';
cout<<mystrcmp(p1,p2)<<'\n';

mystring s("dasfd");
mystring b;
b=s;
cout<<s<<'\n';
cout<<b[1]<<'\n';
}